package game.core
{
	import engine.core.*;
	import engine.network.*;

	import game.network.*;
	import game.ui.core.*;
	import game.ui.hud.*;
	import game.store.*;
	
	import flash.display.*;
	import flash.external.*;
	import flash.system.*;
	
	public class RxExternalInterface
	{
		private static var s_browser:String = "";
		private static var s_heroInitCallback:Function;
		private static var s_heroInitCallbackParams:Array;
		
		public function RxExternalInterface()
		{
		}
		
		public static function LogListener(index:int, s_name:String, arg:String, s_stack:String, bol:Boolean) : void
		{
			if (index >= RxLog.WARNING || bol)
			{
				noteDebugLogLevel_name_stack_hash(RxLog.GetLevelString(index), s_name, s_stack, null);
			}
		}
		
		public static function noteDebugLogLevel_name_stack_hash(s_level:String, s_name:String, s_stack:String, s_hash:String) : void
		{
			var obj:Object = {level:s_level, name:s_name, stack:s_stack, hash:s_hash};
			var info:String = JSON.stringify(obj);
			if (ExternalInterface.available)
			{
				ExternalInterface.call("noteDebugLog", s_level, s_name, info);
			}
		}
		
		public static function Initialize() : void
		{
			if (ExternalInterface.available)
			{
				ExternalInterface.addCallback("handleVisibilityChanged", handleVisibilityChanged);
				ExternalInterface.addCallback("noteHideSwf", noteHideSwf);
				ExternalInterface.addCallback("noteShowSwf", noteShowSwf);
				ExternalInterface.addCallback("openStore", openStore);
				ExternalInterface.addCallback("requestCashin", requestCashin);
				ExternalInterface.addCallback("submitIssue", submitIssue);
			}
		}
		
		public static function handleVisibilityChanged(param1:String) : void
		{
			if (param1 == "visible")
			{
			}
		}
		
		public static function noteHideSwf() : void
		{
			RxSimulation.SendPlayerImmunityRequest(true);
			RxLog.Info("External Interface Call: noteHideSwf: Hiding swf");
		}
		
		public static function noteShowSwf() : void
		{
			//RxStore.instance.SendPaywallEventMessage();
			RxSimulation.SendPlayerImmunityRequest(false);
			RxLog.Info("External Interface Call: noteShowSwf: Restoring swf visibility");
		}
		
		public static function openStore(param1:String) : void
		{
			
		}
		
		public static function requestCashin() : void
		{
			
		}
		
		public static function submitIssue() : void
		{
			
		}
		
		public static function RefreshBrowser() : void
		{
			var _loc_1:String = null;
			if (ExternalInterface.available)
			{
				_loc_1 = "location.reload()";
				ExternalInterface.call(_loc_1);
			}
			else
			{
				fscommand("quit");
			}
		}
		
		public static function GetBrowser() : String
		{
			var userAgent:String;
			var browser:String;
			if (s_browser != "")
			{
				return s_browser;
			}
			try
			{
				userAgent = ExternalInterface.call("window.navigator.userAgent.toString");
				browser;
				if (userAgent.indexOf("Safari") != -1)
				{
					browser;
				}
				if (userAgent.indexOf("Firefox") != -1)
				{
					browser;
				}
				if (userAgent.indexOf("Chrome") != -1)
				{
					browser;
				}
				if (userAgent.indexOf("MSIE") != -1)
				{
					browser;
				}
				if (userAgent.indexOf("Opera") != -1)
				{
					browser;
				}
			}
			catch (e:Error)
			{
				browser;
			}
			s_browser = browser;
			return s_browser;
		}
		
		public static function InitHeartbeat() : void
		{
			var str:String = null;
			if (ExternalInterface.available)
			{
				str = "InitHeartbeat()";
				ExternalInterface.call(str);
			}
		}
	}
}